<?php

class SiteController extends Controller {

    public $layout = 'default';

    /**
     * Declares class-based actions.
     */
    public function actions() {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
            // page action renders "static" pages stored under 'protected/views/site/pages'
            // They can be accessed via: index.php?r=site/page&view=FileName
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }

    public function actionIndex() {
        $categoryModel = new Categorys;
        $subCategorys = $categoryModel->getSubCategorys(5);
        //
        $sbdl = Categorys::model()->findByPk(10);
        $lwpq = Categorys::model()->findByPk(13);
        $rsdl = Categorys::model()->findByPk(16);
        $this->render('index', array(
            'subCategorys' => $subCategorys,
            'sbdl' => $sbdl,
            'lwpq' => $lwpq,
            'rsdl' => $rsdl,
        ));
    }

    public function actionRss() {
        $title = Options::model()->findByAttributes(array('option_label' => 'TITLE'));
        $description = Options::model()->findByAttributes(array('option_label' => 'DESCRIPTION'));
        
        Yii::import('ext.feed.*');
// RSS 2.0 is the default type
        $feed = new EFeed();

        $feed->title = $title->option_value;
        $feed->description = $description->option_value;

        $feed->setImage($title->option_value, Yii::app()->createAbsoluteUrl('site/rss'), 'http://www.szhr360.com/elemente/logo.png');

        $feed->addChannelTag('language', 'zh-CN');
        $feed->addChannelTag('pubDate', date(DATE_RSS, time()));
        $feed->addChannelTag('link', Yii::app()->createAbsoluteUrl('site/rss'));

// * self reference
        //$feed->addChannelTag('atom:link', Yii::app()->createAbsoluteUrl('site/rss'));
        //category
        $categorys = Categorys::model()->findAllByAttributes(array('category_status' => 1));
        foreach ($categorys as $v) {
            $item = $feed->createNewItem();
            $item->title = $v->category_name;
            $item->link = $v->createCategoryUrl();
            $item->date = time();
            $item->description = $v->category_intro;
            $feed->addItem($item);
        }
        //posts

        $feed->generateFeed();
        Yii::app()->end();
    }

    /**
     * This is the action to handle external exceptions.
     */
    public function actionError() {
        if ($error = Yii::app()->errorHandler->error) {
            if (Yii::app()->request->isAjaxRequest)
                echo $error['message'];
            else
                $this->render('error', $error);
        }
    }

}